package com.dev.environment;

import com.dev.environment.bean.EnvironmentBean;
import com.dev.environment.bean.ModuleBean;
import com.dev.environment.listener.OnEnvironmentChangeListener;
import com.dev.utils.app.toast.ToastTintUtils;
import dev.environment.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
import ohos.agp.components.ListContainer;
import ohos.agp.components.Text;
import ohos.os.ProcessManager;

public class DevEnvironmentAbilitySlice extends AbilitySlice {
    private DevEnvironmentChangeListener environmentChangeListener;
     public interface DevEnvironmentChangeListener{
         public void onEnvironmentChanged();
     }
    public DevEnvironmentAbilitySlice(DevEnvironmentChangeListener listener) {
         this.environmentChangeListener=listener;
    }

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        if (Utils.isRelease()) {
            onBackPressed();
            return;
        }
        ToastTintUtils.success("跳转成功");
        super.setUIContent(ResourceTable.Layout_dev_environment);
        Image img= (Image)findComponentById(ResourceTable.Id_vid_dea_back_igview);
        img.setClickedListener(component -> onBackPressed());
        Text restart= (Text)findComponentById(ResourceTable.Id_vid_dea_restart_tv);
        restart.setClickedListener(component -> {
            onBackPressed();
            try {
                // 退出 JVM (Java 虚拟机 ) 释放所占内存资源, 0 表示正常退出、非 0 的都为异常退出
                System.exit(0);
                // 从操作系统中结束掉当前程序的进程
                ProcessManager.kill(ProcessManager.getPid());
            } catch (Exception e) {
                // =
                System.exit(-1);
            }
        });
        AdapterItem.refreshHashCode(this);
        ListContainer vid_dea_listview = (ListContainer) findComponentById(ResourceTable.Id_vid_dea_listview);
        vid_dea_listview.setItemProvider(new ListAdapter(AdapterItem.getAdapterItems(this),this));
        environmentChangeListener.onEnvironmentChanged();
     }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
